<!--_meta 作为公共模版分离出去-->
<!DOCTYPE HTML>
<html>
<head>
    <#include "../common/_meta.html">
    <title>修改密码</title>
</head>
<body>
<article class="cl pd-20">
    <form class="form form-horizontal" id="form-change-password">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">用户名：</label>
            <div class="formControls col-xs-8 col-sm-9">${name}</div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>新密码：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="password" class="input-text" autocomplete="off" placeholder="不修改请留空" name="newpassword" id="newpassword">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>确认密码：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="password" class="input-text" autocomplete="off" placeholder="不修改请留空" name="newpassword2" id="newpassword2">
            </div>
        </div>
        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;保存&nbsp;&nbsp;">
            </div>
        </div>
    </form>
</article>

<#include "../common/_footer.html">

<script type="text/javascript">
    $(function(){
        $("#form-change-password").validate({
            rules:{
                newpassword:{
                    required:true,
                    minlength:6,
                    maxlength:16
                },
                newpassword2:{
                    required:true,
                    minlength:6,
                    maxlength:16,
                    equalTo: "#newpassword"
                },
            },
            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(form){
                invoke();
            }
        });
    });

    function invoke() {
        var name = '${name}';
        var password = $("#newpassword").val();
        var index = layer.load(2);
        $.ajax({
            type: "POST",
            url: "${base}/user/changePwd",
            data: {"name": name,"password": password},
            dataType: "json",
            success: function (result) {
                layer.close(index);
                if(result.code === 0) {
                    layer.msg("修改成功", {icon:6,time:1000}, function () {layer_close();});
                } else {
                    layer.alert("修改失败", {icon:5,time:1000}, function () {layer_close();});
                }
            },
            error: function (result) {
                layer.close(index);
                layer.msg("内部错误", {icon:5,time:2000}, function () {layer_close();});
            }

        });
    }
</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>